package text;


import pers.mydb.ORM.ObjectRelationMapping;
import pers.mydb.connection.DBConnection;
import pers.mydb.connection.configuration.Configuration;
import pers.mydb.throwable.MyDBException;
import pers.myutil.throwable.local.MyUtilLocalException;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

public class Text {

    public static void main(String[] args) throws MyDBException, SQLException, NoSuchMethodException, IntrospectionException, IllegalAccessException, InstantiationException, MyUtilLocalException, InvocationTargetException {
        Configuration configuration = new Configuration.Builder()
                .addDbUser("root")
                .addDbPassword("123456")
                .addDbDriverClass("com.mysql.cj.jdbc.Driver")
                .addDbUrl("jdbc:mysql://118.24.123.122:3306/distribution?autoReconnect=true&useSSL=false&serverTimezone=UTC&characterEncoding=utf8")
                .build();

        Connection connection = DBConnection.getConfiguration(configuration);
        String sql = "SELECT * FROM user";
        PreparedStatement pst = connection.prepareStatement(sql);
        ResultSet resultSet = pst.executeQuery();
        Map<String,Object> maps = ObjectRelationMapping.handleResultSetToMap(resultSet);
        System.out.println(((User)ObjectRelationMapping.transfterMapToBeanUnique(User.class,maps)));
//        for(User user : (List<User>)ObjectRelationMapping.transfterMapToBeanList(User.class,maps)){
//            System.out.println(user.toString());
//        }

//        UserThread userThread = new UserThread("线程1==");
//        userThread.start();
//        userThread = new UserThread("线程2 ==");
//        userThread.start();
    }

}
